#include <iostream>
#include <algorithm>
#include <iterator>
#include <ostream>
#include <vector>

using namespace std;


int main() {
  vector myvec{5, 6, 9, 8, 8, 3};
  auto beginIter {cbegin(myvec)};
  auto endIter{cend(myvec)};
  
  auto it {find_if_not(beginIter, endIter, [](int i) {return i < 8;})};

  if(it != endIter) {
    cout << "First element not < 8 is " << *it << endl;
  }

  it = adjacent_find(beginIter, endIter);

  if (it != endIter) {
    cout << "found two consecutive equal elements with value " << *it << endl;
  }

  vector targets {8, 9};

  it = find_first_of(beginIter, endIter, cbegin(targets), cend(targets));

  if (it != endIter) {
    cout << "found one of 8 or 9: " << *it << endl;
  }

  vector sub{8, 3};
  it = search(beginIter, endIter, cbegin(sub), cend(sub));

  if (it != endIter) {
    cout << "found subsequece {8, 3}" << endl;
  } else {
    cout << "unable to find subsequence {8, 3}" << endl;
  }

  auto it2 {find_end(beginIter, endIter, cbegin(sub), cend(sub))};

  if (it2 != it) {
    cout << "Error: search and find_end found different subsequences " <<
    "even though there is only one match" << endl;
  }

  it=search_n(beginIter, endIter, 2, 8);
  if (it != endIter) {
    cout << "found two consecutive 8s" << endl;
  } else {
    cout << "unable to fnind two consecutive 8s" << endl;
  }

  return 0;

}
